import time
import scrapy
from crawler.items import BaseItem

__all__ = ['TraceItem', 'ReplyItem', 'ContainerTraceItem', 'PortTraceItem', 'PortShipTraceItem',
           'PortShipTraceListItem', 'NewPortShipTraceItem']


class TraceItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 订单号
    referenceNo = scrapy.Field(type=str)  # 订舱号转订单号
    bookingInfo = scrapy.Field(type=dict)  # 订舱信息
    shippingInfo = scrapy.Field(type=list)  # 航段信息
    containerInfo = scrapy.Field(type=list)  # 集装箱信息
    containerStatusInfo = scrapy.Field(type=list)  # 集装箱状态信息

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_trace'
        self['fetchTime'] = int(time.time() * 1000)


class ContainerTraceItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 订单号
    bookingInfo = scrapy.Field(type=dict)  # 订舱信息
    containerInfo = scrapy.Field(type=list)  # 集装箱信息
    shippingInfo = scrapy.Field(type=list)  # 航段信息
    containerStatusInfo = scrapy.Field(type=list)  # 集装箱状态信息

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_container_trace'
        self['fetchTime'] = int(time.time() * 1000)


class PortTraceItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 查询订单号/订舱号/箱号
    containerBaseInfo = scrapy.Field(type=list)  # 基础信息
    containerDetailInfo = scrapy.Field(type=list)  # 详情信息
    containerCustomsInfo = scrapy.Field(type=list)  # 报关信息
    containerChangeInfo = scrapy.Field(type=list)  # 改配信息
    containerLoadInfo = scrapy.Field(type=list)  # 装载放行
    containerDoorInfo = scrapy.Field(type=list)  # 进出门
    containerTerminalInfo = scrapy.Field(type=list)  # 码头信息
    containerArriveReportInfo = scrapy.Field(type=list)  # 运抵报告
    containerDeclarationInfo = scrapy.Field(type=list)  # 申报信息
    containerManifestReleaseInfo = scrapy.Field(type=list)  # 新舱单放行
    containerManifestConfigInfo = scrapy.Field(type=list)  # 新舱单配置

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_port_trace'
        self['fetchTime'] = int(time.time() * 1000)


class PortShipTraceItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 查询船名/航次
    wharf = scrapy.Field(type=str)  # 码头
    terminal = scrapy.Field(type=str)  # 码头
    status = scrapy.Field(type=str)  # 状态
    shipCompanyName = scrapy.Field(type=str)  # 船公司名
    chnShipName = scrapy.Field(type=str)  # 中文船名
    engShipName = scrapy.Field(type=str)  # 英文船名
    importShipNo = scrapy.Field(type=str)  # 进口航次
    exportShipNo = scrapy.Field(type=str)  # 出口航次
    importWeight = scrapy.Field(type=str)  # 进口箱量
    exportWeight = scrapy.Field(type=str)  # 出口箱量
    loadAtWharfST = scrapy.Field(type=str)  # 码头进箱开始时间
    loadAtWharfDT = scrapy.Field(type=str)  # 码头进箱截止时间
    dangerousLoadAtWharfST = scrapy.Field(type=str)  # 码头危险品进箱开始时间
    dangerousLoadAtWharfDT = scrapy.Field(type=str)  # 码头危险品进箱截止时间
    portCutOrderTime = scrapy.Field(type=str)  # 港区截单时间
    berthTime = scrapy.Field(type=str)  # 靠泊时间
    departureTime = scrapy.Field(type=str)  # 离泊时间
    planBerthTime = scrapy.Field(type=str)  # 计划靠泊时间
    actualBerthTime = scrapy.Field(type=str)  # 实际靠泊时间
    planDepartureTime = scrapy.Field(type=str)  # 计划离泊时间
    actualDepartureTime = scrapy.Field(type=str)  # 实际离泊时间
    predictionOrConfirmation = scrapy.Field(type=str)  # 预报/确保
    planArriveAnchorageTime = scrapy.Field(type=str)  # 计划抵锚地时间
    actualArriveAnchorageTime = scrapy.Field(type=str)  # 计划抵锚地时间
    planArrivePortTime = scrapy.Field(type=str)  # 预计到港时间
    actualArrivePortTime = scrapy.Field(type=str)  # 实际到港时间
    planDeparturePortTime = scrapy.Field(type=str)  # 预计离港时间
    actualDeparturePortTime = scrapy.Field(type=str)  # 实际离港时间
    berthLocation = scrapy.Field(type=str)  # 抵港位置
    shipType = scrapy.Field(type=str)  # 船舶类型
    previousPort = scrapy.Field(type=str)  # 上一港
    domesticAndForeignTrade = scrapy.Field(type=str)  # 内外贸
    dayOrNightPlan = scrapy.Field(type=str)  # 昼夜计划
    isDeparture = scrapy.Field(type=str)  # 是否已离泊
    shipLine = scrapy.Field(type=str)  # 航线
    shipLineType = scrapy.Field(type=str)  # 航线类型
    berth = scrapy.Field(type=str)  # 泊位
    shipUN = scrapy.Field(type=str)  # 船舶UN代码
    agent = scrapy.Field(type=str)  # 代理
    queryType = scrapy.Field(type=str)  # 查询类型

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_port_ship'
        self['fetchTime'] = int(time.time() * 1000)


class NewPortShipTraceItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 查询船名/航次
    wharf = scrapy.Field(type=str)  # 码头
    status = scrapy.Field(type=str)  # 状态
    carrier = scrapy.Field(type=str)  # 船公司名
    vslNameZh = scrapy.Field(type=str)  # 中文船名
    vslNameEn = scrapy.Field(type=str)  # 英文船名
    importVoy = scrapy.Field(type=str)  # 进口航次
    exportVoy = scrapy.Field(type=str)  # 出口航次
    importQuantity = scrapy.Field(type=str)  # 进口箱量
    exportQuantity = scrapy.Field(type=str)  # 出口箱量
    loadAtWharfST = scrapy.Field(type=str)  # 码头进箱开始时间
    loadAtWharfDT = scrapy.Field(type=str)  # 码头进箱截止时间
    dangerousLoadAtWharfST = scrapy.Field(type=str)  # 码头危险品进箱开始时间
    dangerousLoadAtWharfDT = scrapy.Field(type=str)  # 码头危险品进箱截止时间
    terminalCutOffTime = scrapy.Field(type=str)  # 港区截单时间
    ETB = scrapy.Field(type=str)  # 计划靠泊时间
    ATB = scrapy.Field(type=str)  # 实际靠泊时间
    predictionOrConfirmation = scrapy.Field(type=str)  # 预报/确保
    ETA = scrapy.Field(type=str)  # 预计到港时间
    ATA = scrapy.Field(type=str)  # 实际到港时间
    ETD = scrapy.Field(type=str)  # 预计离港时间
    ATD = scrapy.Field(type=str)  # 实际离港时间
    position = scrapy.Field(type=str)  # 抵港位置
    vesselType = scrapy.Field(type=str)  # 船舶类型
    previousPort = scrapy.Field(type=str)  # 上一港
    domesticAndForeignTrade = scrapy.Field(type=str)  # 内外贸
    dayOrNightPlan = scrapy.Field(type=str)  # 昼夜计划
    shipLine = scrapy.Field(type=str)  # 航线
    shipLineType = scrapy.Field(type=str)  # 航线类型
    berth = scrapy.Field(type=str)  # 泊位
    shipUN = scrapy.Field(type=str)  # 船舶UN代码
    agent = scrapy.Field(type=str)  # 代理
    queryType = scrapy.Field(type=str)  # 查询类型
    loadShipTime = scrapy.Field(type=str)  # 装船时间
    closingTime = scrapy.Field(type=str)  # 关闸时间
    approachEndTime = scrapy.Field(type=str)  # 截止进场

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_port_ship'
        self['fetchTime'] = int(time.time() * 1000)


class PortShipTraceListItem(BaseItem):
    _id = scrapy.Field(type=str)
    dataId = scrapy.Field(type=str)  # 等同于mongo的_id
    fetchTime = scrapy.Field(type=int)  # 抓取时间
    trackingNo = scrapy.Field(type=str)  # 查询船名/航次
    portShipList = scrapy.Field(type=list)  # 船期列表

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_port_ship_list'
        self['fetchTime'] = int(time.time() * 1000)


class ReplyItem(BaseItem):
    replyTime = scrapy.Field(type=int)  # 回执时间
    dataId = scrapy.Field(type=str)  # 返回数据ID
    status = scrapy.Field(type=int)  # 抓取状态
    errorMsg = scrapy.Field(type=str)  # 抓取失败说明

    def __init__(self):
        super().__init__()
        self['type'] = 'sea_reply'
        self['replyTime'] = int(time.time() * 1000)
